import axios from 'axios'

const ajax = axios.create({
  baseURL: window.BASE_URL
})

// const request = req => {
export default req => {
  return new Promise(resolve => {
    ajax
      .request({
        url: req.url,
        method: req.method || 'GET' || 'POST',
        params: req.params || {},
        data: req.data || {}
      })
      .then(({ data }) => {
        resolve(data)
      })
      .catch(e => {
        resolve(e)
      })
  })
}

// export default request
